﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;
public partial class payroll_payroll_general : System.Web.UI.Page
{
    public DataSet payrollarr = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] != null) {
            RE_GenericBean rg = (RE_GenericBean)Session["user"];
            if (!rg.strC6.ToUpper().Equals("ADMIN") && !rg.strC6.ToUpper().Equals("ACCOUNTING"))
            {
                Response.Redirect(Request.UrlReferrer.ToString());
            }
        
        }
        payrollarr = (DataSet)DB.getArrPayroll("");
        if (!Page.IsPostBack) {
            gv_general.DataSource = payrollarr;
            gv_general.DataBind();
            //voy a traer precio orden extra
            ArrayList ar = DB.getSettings("");
            foreach (RE_GenericBean r in ar) {
                if (r.strC1.Equals("EXTRAORDER")) {
                    lb_extraorder.Text = r.decC1.ToString();
                }
            }
        }
    }
        
    protected void gv_general_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header) {
            e.Row.Cells[0].Visible = false;
            e.Row.Cells[4].Visible = false;
            e.Row.Cells[6].Visible = false;
            e.Row.Cells[7].Visible = false;
            e.Row.Cells[0].Attributes.Add("Style", " text-align: left;");
            e.Row.Cells[1].Attributes.Add("Style", " text-align: left;");
            e.Row.Cells[2].Attributes.Add("Style", " text-align: left;");
            e.Row.Cells[3].Attributes.Add("Style", " text-align: left;");
            e.Row.Cells[4].Attributes.Add("Style", " text-align: left;");
            e.Row.Cells[5].Attributes.Add("Style", " text-align: left;");
          
        
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].Visible = false;
            e.Row.Cells[4].Visible = false;
            e.Row.Cells[6].Visible = false;
            e.Row.Cells[7].Visible = false;
            if (e.Row.Cells[5].Text.Equals("1"))
            {
                e.Row.Cells[5].Text = "<img src='images/icons/action_check.gif' alt='' >";
            }
            else {
                e.Row.Cells[5].Text = "<img src='images/icons/edit.gif' alt='' >";
            
            }
          
            HyperLink hy = new HyperLink();
            hy.Text = e.Row.Cells[1].Text;
            hy.NavigateUrl = "payroll.aspx?payroll=" + e.Row.Cells[0].Text;
            hy.Target = "_blank";
            e.Row.Cells[1].Controls.Add(hy);
            e.Row.Cells[0].Attributes.Add("Style", " text-align: left;");
            e.Row.Cells[1].Attributes.Add("Style", " text-align: left;");
            e.Row.Cells[2].Attributes.Add("Style", " text-align: left;");
            e.Row.Cells[3].Attributes.Add("Style", " text-align: left;");
            e.Row.Cells[4].Attributes.Add("Style", " text-align: left;");
         
        }

    }
    protected void LinkButton4_Click(object sender, EventArgs e)
    {
        LinkButton4.Enabled = false;
        if (!tb_name.Text.Equals("") && !tb_stdatepop.Text.Equals("") && !tb_enddatepop.Text.Equals(""))
        {
            RE_GenericBean re = new RE_GenericBean();
            re.strC1 = tb_name.Text;
            re.strC2 = tb_stdatepop.Text;
            re.strC3 = tb_enddatepop.Text;
            re.decC1 = Decimal.Parse(lb_extraorder.Text);
            int res = DB.insertPayroll(re, false);
            payrollarr = (DataSet)DB.getArrPayroll("");
            if (payrollarr != null)
            {
                gv_general.DataSource = payrollarr;
                gv_general.DataBind();
                tb_name.Text = "";
                tb_stdatepop.Text = "";
                tb_enddatepop.Text = "";
                
            }
            if (res != 0)
            {
                Response.Write("<script type='text/javascript'>window.open('payroll.aspx?payroll='"+res+");</script>"); 
                
            }
            LinkButton4.Enabled = true;
            Response.Redirect("payroll_general.aspx");



        }
        else {

            Response.Write("<alert text='One or more Elements Missing'");
        }
    }
    protected void bt_cancel_Click(object sender, EventArgs e)
    {
        tb_name.Text = "";
        tb_stdatepop.Text = "";
        tb_enddatepop.Text = "";
        tb_comments.Text = "";
        Panel_Add_Extender.Hide();
    }
   
}